package com.u.auth.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.u.auth.model.vo.UserVO;
import com.u.auth.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.u.common.api.ApiResponse;

/**
 * @program: u-social
 * @description: 授权控制器
 * @author: Alex Wu
 * @createDate: 2025-01-22 16:13
 **/

@RestController
@RequestMapping("/sso")
public class SSOController {

    @Autowired
    private AuthService authService;

    @PostMapping(value = "/login/password")
    public ApiResponse<UserVO>  login(@RequestParam String username, @RequestParam String password) {
        UserVO userVO = authService.login(username, password);
        if (userVO == null) {
            return ApiResponse.fail(400,"用户名或密码错误");
        }
        return ApiResponse.success(userVO);
    }

    @GetMapping(value = "/login/status")
    public Boolean  getLoginStatus() {
        return StpUtil.isLogin();
    }
}
